package java_collection.lab;

import java.util.HashMap;
import java.util.Map;

public class Freq {
	static String s = "if it is to be it is up to me to delegate";
	
	public static void main(String[] args) {
        Map<String, Integer> m = new HashMap<String, Integer>();
        
        String[] list = s.split(" ");
        // Initialize frequency table from command line
        Integer oldFreq, newFreq;
        
        System.out.printf("Evaluation string = %s %n%n" , s);
        for (String word : list) {
            oldFreq = m.get(word);
            newFreq = (oldFreq == null) ? 1 : oldFreq + 1;
            System.out.printf("word = %s, old freq = %d, new freq =  %d %n", word,oldFreq,newFreq);
            m.put(word, newFreq);
        }

        System.out.printf("%d distinct words:%n", m.size());
        System.out.println(m);
    }
}
